#include <iostream>
using namespace std;
const int FRONT = -1;
const int TAIL = -2;
int N, M;
int k, p, x;
enum
{
    LEFT,
    RIGHT
};
struct node
{
    int num;
    node *left, *right;
    node(int num = 0, node *left = NULL, node *right = NULL)
        : num(num), left(left), right(right){};
};
struct Queue
{
    node *front, *tail;
    Queue()
    {
        front = new node(FRONT);
        tail = new node(TAIL);
        front->right = tail;
        tail->left = front;
    }
    node *find(int elem);
    void insertL(int elem, int val);
    void insertR(int elem, int val);
    void insert(int elem, int pos, int val);
    void deque(int elem);
    void showQue();
};
node *Queue::find(int elem)
{
    node *tmp = front;
    while (tmp)
    {
        if (tmp->num == elem)
            return tmp;
        else
            tmp = tmp->right;
    }
    return NULL;
}
void Queue::insertL(int elem, int val)
{
    node *q = find(elem);
    if (q != NULL) //因为安排了队首元素front,所以q的左边一定不是null
    {
        q->left->right = new node(val, q->left, q);
    }
}
void Queue::insertR(int elem, int val)
{
    node *q = find(elem);
    if (q != NULL) //因为安排了队尾元素tail,所以q的右边一定不是null
    {
        q->right->left = new node(val, q, q->right);
    }
}
void Queue::insert(int elem, int pos, int val)
{
    if (pos == LEFT)
        insertL(elem, val);
    else
        insertR(elem, val);
}
void Queue::deque(int elem)
{
    node *q = find(elem);
    if (q != NULL)
    {
        q->left->right = q->right;
        q->right->left = q->left;
    }
}
void Queue::showQue()
{
    for (node *i = front; i != tail; i = i->right)
        if (i != front && i != tail)
            cout << i->num << " ";
}
int main()
{
    cin >> N;
    Queue que;
    que.insertR(FRONT, 1);
    for (int i = 2; i <= N; ++i)
    {
        cin >> k >> p;
        que.insert(k, p, i);
    }
    cin >> M;
    for (int i = 0; i < M; ++i)
    {
        cin >> x;
        que.deque(x);
    }
    que.showQue();
    return 0;
}